// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'

// 自定义指令
import directive from './directives'
//注册使用自定义指令
Vue.use(directive)

// 导入公共样式
import "@/assets/less/common.less"

// 引入element-ui
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

// 安装ElementUI 提供的全局组件
Vue.use(ElementUI)
Vue.config.productionTip = false

//导入封装好的axios插件
import httpAxios from './http'
//使用自己封装好的插件
Vue.use(httpAxios)

//本地检测token是否已经过期
if (store.state.user.info.token_exp && Date.now() > (store.state.user.info.token_exp * 1000)) {
  //清空本地的用户记录 ， 再跳转到登录页
  store.dispatch('user/logout').then(() => {
    //跳转
    // console.log(store);
    let redirectUrl = router.currentRoute.fullPath || '/';//获取当前路由的地址
    router.push({
      path:'/login',
      query:{
        redirect:redirectUrl
      }
    });
  });
}

/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  router,
  components: { App },
  template: '<App/>'
})
